// miniprogram/pages/ch_zhujiahao/ch_zhujiahao.js
import sendRequest from "../../util/sendRequest"
Page({
  chLst(){
    sendRequest({
      url: "chListZJH",
      method: "GET",
      data: {
        bookid: this.data.bid
      },
      success: res => {
        this.setData({
          chLst: res.data.data
        })
        console.log("success", res)
        if (res.data.code == 200) {
          wx.showToast({
            title: res.data.msg,
            icon: 'success'
          })
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
      },
      fail: res => {
        console.log("fail", res)
      },
      complete: res => {
        console.log("complete", res)
      }
    })
  },
  logicDelete(e){
    var chId = e.currentTarget.dataset.id
    wx.showModal({
      title: '提示',
      content: '确认删除该章节吗?',
      success: res => {
        if (res.confirm) {
          sendRequest({
            url: "chDeleteZJH",
            method: "GET",
            data: {
              id: chId
            },
            success: res => {
              console.log("success", res)
              if (res.data.code == 200) {
                wx.showToast({
                  title: '您已' + res.data.msg, success: res => {
                    icon: 'success'
                    this.chLst()
                  }
                })
              } else {
                wx.showToast({
                  title: res.data.msg,
                  icon: 'none'
                })
              }
            },
            fail: res => {
              console.log("fail", res)
            },
            complete: res => {
              console.log("complete", res)
            }
          })
        }
      }
    })
  },

  //进入编辑页面
  goUpdateId(e) {
    // console.log(e)
    var chId = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/ch-add_zhujiahao/ch-add_zhujiahao?id=' + chId,
    })
  },
  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.bid=options.bookid
    wx.showToast({
      title: '正在查询数据',
      icon: 'loading',
      duration: 9000
    })
    sendRequest({
      url: "chListZJH",
      method: "GET",
      data: {
        bookid: this.data.bid
      },
      success: res => {
        this.setData({
          chLst: res.data.data
        })
        console.log("success", res)
        if (res.data.code == 200) {
          wx.showToast({
            title: res.data.msg,
            icon: 'success'
          })
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
      },
      fail: res => {
        console.log("fail", res)
      },
      complete: res => {
        console.log("complete", res)
      }
    }),
      sendRequest({
        url: "bookCheckAllZJH",
        method: "GET",
        success: res => {
          this.setData({
            bookLst: res.data.data
          })
          console.log("success", res)
          if (res.data.code == 200) {
            wx.showToast({
              title: res.data.msg,
              icon: 'success'
            })
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            })
          }
        },
        fail: res => {
          console.log("fail", res)
        },
        complete: res => {
          console.log("complete", res)
        }
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.chLst()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})